#ifndef CARVERBRUSH_H
#define CARVERBRUSH_H

#include <BMap>
#include <BSet>
#include <BIcon>
#include <BImage>
#include <BPicker>
#include <BHandler>
#include <BCircle>
#include <BTerrain>

#include "CarverDialog.h"

class CarverHandler : public BHandler
{
public:
	CarverHandler();
	~CarverHandler();

	void setBrushSize(int size);
	int brushSize() const;

	void setIntensity(BReal intensity);
	BReal intensity() const;

	void setDynamic(bool dynamic);
	bool dynamic() const;

	void setDynamicRatio(BReal dynamicRatio);
	BReal dynamicRatio() const;

	void setPointsVisible(bool pointsVisible);
	bool pointsVisible() const;

protected:
	void catchOnTerrain();
	void applyOnTerrain();

protected:
	void slotPanelClosed();
	void slotAssetChanged();

protected:
	virtual void paint(BPainter& painter);
	virtual void render(BRender& render);

	virtual void resizeEvent(const BEvent& event);
	virtual void updateEvent(const BEvent& event);

	virtual void keyPressEvent(const BKeyEvent& keyEvent);
	virtual void keyReleaseEvent(const BKeyEvent& keyEvent);

	virtual void mousePressEvent(const BMouseEvent& mouseEvent);
	virtual void mouseReleaseEvent(const BMouseEvent& mouseEvent);
	virtual void mouseMoveEvent(const BMouseEvent& mouseEvent);

	virtual void mouseClickEvent(const BMouseEvent& mouseEvent);

private:
	int					_brushSize;
	BReal				_intensity;
	bool				_dynamic;
	BReal				_dynamicRatio;
	bool				_pointsVisible;

	BPickHitHolder		_pickHit;
	BCircle				_brushCircle;
	BColor				_brushColor;

	bool				_pressed;
	bool				_shiftDown;
	bool				_ctrlDown;
	bool				_altDown;

	struct PointInfo
	{
		void addLinks(int i0, int i1)
		{
			if (!links.contain(i0))
				links.append(i0);
			if (!links.contain(i1))
				links.append(i1);
		}
		char			state;
		BIntArray		links;
	};
	BArray<PointInfo>	_pointInfos;
	BArray<int>		_indexsCatched;
	BHolder<BTerrain>	_terrain;
};

#endif